﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="false"
    CodeFile="recRegistrationlist.aspx.cs" Inherits="SIPO.Web.Lists.Transaction.recRegistrationlist" %>

<asp:Content ID="ctnBody" ContentPlaceHolderID="body" runat="server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveUrl("~/scripts/helper.js") %>" type="text/javascript"></script>
    <div>
        <%--<a href="#" id="dialog_link" class="dialog_link ui-state-default ui-corner-all" alt="Add"
            onclick="OpenForm('add')"><span class="ui-icon ui-icon-plus"></span>Add</a>
        <a href="#" id="dialog_link" class="dialog_link ui-state-default ui-corner-all" alt="Edit"
            onclick="OpenForm('edit');"><span class="ui-icon ui-icon-pencil"></span>Edit</a>
        <a href="#" id="dialog_link" class="dialog_link ui-state-default ui-corner-all" alt="Delete"
            onclick="OpenForm('delete');"><span class="ui-icon ui-icon-trash"></span>Delete</a>
        <a href="#" id="dialog_link" class="dialog_link ui-state-default ui-corner-all" alt="Delete"
            onclick="OpenForm('updatestatus');"><span class="ui-icon ui-icon-pencil"></span>
            Update Status</a>--%>
        <button id="btnAdd" type="button" onclick="OpenForm('add');">
            Tambah</button>
        <button id="btnEdit" type="button" onclick="OpenForm('edit');">
            Ubah</button>
        <button id="btnApprove" type="button" onclick="OpenForm('updatestatus');">
            Ubah Status</button>
    </div>
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog1" title="Default dialog">
    </div>
    <asp:HiddenField ID="hfSubSectorName" runat="server" />
    <script type="text/javascript">

        $("#btnAdd").button({ icons: { primary: "ui-icon-plus"} });
        $("#btnEdit").button({ icons: { primary: "ui-icon-pencil"} });
        $("#btnApprove").button({ icons: { primary: "ui-icon-pencil"} });

    </script>
    <script type="text/javascript">
        var subsectorname = $('#<%= hfSubSectorName.ClientID %>').val();
        var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recRegistrationhandler.ashx") %>';
        if (subsectorname == "emiten" || subsectorname == "perusahaan publik") {
            $('#table').jqGrid({
                url: handlerUrl + '?method=getdata',
                datatype: 'json',
                colNames: ['ID', 'RegistrationId', 'Nama Perusahaan', 'Sector', 'Sub Sector', 'Sub Sub Sector', 'Dasar Perhitungan (Rp)', 'Nilai Tagihan (Rp)', 'No Surat Setoran', 'No Pembayaran', 'Status Registrasi', 'Status Perusahaan', 'Jenis Penawaran Umum'],
                colModel: [
           		{ name: 'recSectorRegistration.SectorRegistrationID', hidden: true, index: 'SectorRegistrationID', width: 5 },
                { name: 'RegistrationID', hidden: true, index: 'RegistrationID', width: 5 },
           		{ name: 'PreDebtorName', index: 'PreDebtorName', width: 200 },
                { name: 'recSector.SectorName', index: 'SectorName', width: 200, hidden: true, searchoptions: { searchhidden: true} },
                { name: 'recSubSector.SubSectorName', index: 'SubSectorName', width: 200, hidden: true, searchoptions: { searchhidden: true} },
                { name: 'recSubSubSector.SubSubSectorName', index: 'SubSubSectorName', width: 200 },
                { name: 'recSectorRegistration.EmisionValue', index: 'EmisionValue', width: 130, formatter: 'currency', formatoptions: { prefix: '', suffix: '', thousandsSeparator: ',' }, align: 'right' },
                { name: 'recInvoiceDetail.Value', index: 'Value', width: 100, formatter: 'currency', formatoptions: { prefix: '', suffix: '', thousandsSeparator: ',' }, align: 'right' },
                { name: 'recInvoice.InvoiceNo', index: 'InvoiceNo', align: 'center', width: 100 },
                { name: 'recInvoice.PaymentNo', index: 'PaymentNo', align: 'center', width: 100 },
                { name: 'recRegistrationStatus.RegistrationStatusName', index: 'RegistrationStatusName', width: 200 },
                { name: 'IsActive', hidden: true, index: 'ISACTIVE', width: 100, align: 'Center', formatter: 'checkbox', formatoptions: { disabled: true} },
                { name: 'recSectorRegistration.recRegistrationEmisionType.RegistrationEmisionTypeName', index: 'RegistrationEmisionTypeName', width: 300 }
           	],
                rowNum: 10,
                id: 'SectorRegistrationID',
                multiselect: true,
                rowList: [5, 10, 15, 20],
                pager: '#pager',
                sortname: 'SectorRegistrationID',
                sortorder: "asc",
                viewrecords: true,
                jsonReader: { repeatitems: false },
                height: '100%',
                caption: 'Daftar Registrasi',
                ajaxGridOptions: { cache: false },
                ondblClickRow: function () {
                    OpenForm('edit');
                }
            })
        }
        else {
            $('#table').jqGrid({
                url: handlerUrl + '?method=getdata',
                datatype: 'json',
                colNames: ['ID', 'RegistrationId', 'Nama Perusahaan', 'Sector', 'Sub Sector', 'Sub Sub Sector', 'Dasar Perhitungan (Rp)', 'Nilai Tagihan (Rp)', 'No Surat Setoran', 'No Pembayaran', 'Status Registrasi', 'Status Perusahaan'],
                colModel: [
           		{ name: 'recSectorRegistration.SectorRegistrationID', hidden: true, index: 'SectorRegistrationID', width: 5 },
                { name: 'RegistrationID', hidden: true, index: 'RegistrationID', width: 5 },
           		{ name: 'PreDebtorName', index: 'PreDebtorName', width: 200 },
                { name: 'recSector.SectorName', index: 'SectorName', width: 200, hidden: true, searchoptions: { searchhidden: true} },
                { name: 'recSubSector.SubSectorName', index: 'SubSectorName', width: 200, hidden: true, searchoptions: { searchhidden: true} },
                { name: 'recSubSubSector.SubSubSectorName', index: 'SubSubSectorName', width: 200 },
                { name: 'recSectorRegistration.EmisionValue', index: 'EmisionValue', width: 130, formatter: 'currency', formatoptions: { prefix: '', suffix: '', thousandsSeparator: ',' }, align: 'right' },
                { name: 'recInvoiceDetail.Value', index: 'Value', width: 100, formatter: 'currency', formatoptions: { prefix: '', suffix: '', thousandsSeparator: ',' }, align: 'right' },
                { name: 'recInvoice.InvoiceNo', index: 'InvoiceNo', align: 'center', width: 100 },
                { name: 'recInvoice.PaymentNo', index: 'PaymentNo', align: 'center', width: 100 },
                { name: 'recRegistrationStatus.RegistrationStatusName', index: 'RegistrationStatusName', width: 200 },
                { name: 'IsActive', hidden: true, index: 'ISACTIVE', width: 100, align: 'Center', formatter: 'checkbox', formatoptions: { disabled: true} }
           	],
                rowNum: 10,
                id: 'SectorRegistrationID',
                multiselect: true,
                rowList: [5, 10, 15, 20],
                pager: '#pager',
                sortname: 'SectorRegistrationID',
                sortorder: "asc",
                viewrecords: true,
                jsonReader: { repeatitems: false },
                height: '100%',
                caption: 'Daftar Registrasi',
                ajaxGridOptions: { cache: false },
                ondblClickRow: function () {
                    OpenForm('edit');
                }
            })
        }

        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true });
        hidecoloumn();

        function OpenForm(ctl) {
            var subsectorname = $('#<%= hfSubSectorName.ClientID %>').val();
            var formUrl = '<%= ResolveUrl("~/forms/transaction/recRegistrationform.aspx") %>';
            var formUrlChekNPWP = '<%= ResolveUrl("~/forms/transaction/recRegistrationDebtorAfterform.aspx") %>';
            var formUpdateStatusRegistrationUrl = '<%= ResolveUrl("~/forms/transaction/recRegistrationStatusUpdate.aspx") %>';

            var grid = $('#table');
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'recSectorRegistration.SectorRegistrationID'));
            });
            selTextRegistrationId = [];
            $.each(selIds, function () {
                selTextRegistrationId.push(grid.jqGrid('getCell', this, 'RegistrationID'));
            });
            selTextPaymentNo = [];
            $.each(selIds, function () {
                selTextPaymentNo.push(grid.jqGrid('getCell', this, 'recInvoice.PaymentNo'));
            });
            selTextInvoiceNo = [];
            $.each(selIds, function () {
                selTextInvoiceNo.push(grid.jqGrid('getCell', this, 'recInvoice.InvoiceNo'));
            });
            selTextRegistrationStatusName = [];
            $.each(selIds, function () {
                selTextRegistrationStatusName.push(grid.jqGrid('getCell', this, 'recRegistrationStatus.RegistrationStatusName'));
            });
            if (ctl == 'edit') {
                if (selIds.length == 0)
                    alert('Pilih data yang mau di edit!');
                else {
                    if (selIds.length > 1) {
                        alert('Pilih satu record untuk ubah data!');
                    }
                    else if (selIds.length == 1) {
                        $('#dialog1').load(formUrl + '?id=' + selText + '&invoiceno=' + selTextInvoiceNo).dialog({ autoOpen: false, modal: true, width: 1000, title: 'Edit Registrasi' });
                        $("#dialog1").dialog('open');
                    }
                }
            }
            else if (ctl == 'add') {
                if (subsectorname == "emiten" || subsectorname == "perusahaan publik")
                    $('#dialog1').load(formUrl + '?RegInternal=1').dialog({ autoOpen: false, modal: true, width: 1000, title: 'Add Penawaran Umum' });
                else
                    $('#dialog1').load(formUrl + '?RegInternal=1').dialog({ autoOpen: false, modal: true, width: 1000, title: 'Add Registrasi' });
                $("#dialog1").dialog('open');
            }
            else if (ctl == 'delete') {
                if (selIds.length == 0)
                    alert('Pilih data yang mau di hapus!');
                else {
                    var result = window.confirm('Apakah Anda yakin untuk menghapus data ini?');
                    if (result) {
                        if (selTextPaymentNo == "") {
                            var objrecRegistration = new Object();
                            objrecRegistration.SectorRegistrationID = encodeURIComponent(selText);

                            jsonData = JSON.stringify(objrecRegistration);

                            CallAjax('<%= ResolveUrl("~/AjaxHandler/Transaction/recRegistrationhandler.ashx") %>', "?method=setnonactive", jsonData);

                            setTimeout("$('#table').trigger('reloadGrid');", 3000);
                        }
                        else {
                            alert('Data Tidak bisa di hapus, sudah ada pembayaran');
                        }
                    }
                }
            }
            else if (ctl == 'updatestatus') {
                if (selIds.length == 0)
                    alert('Pilih data yang mau di update status registrasi!');
                else {
                    if (selIds.length > 1) {
                        alert('Pilih satu record untuk pdate status!');
                    }
                    else if (selIds.length == 1) {
                        if (selTextPaymentNo == "")
                            alert('Tidak dapat update status , karena belum ada pembayaran !');
                        else {
                            if (selTextRegistrationStatusName.toString().toLowerCase().indexOf('sedang') > 0)
                                $('#dialog1').load(formUpdateStatusRegistrationUrl + '?id=' + selText + '&registrationId=' + selTextRegistrationId + '&invoiceno=' + selTextInvoiceNo).dialog({ autoOpen: false, modal: true, width: 400, title: 'Update Status Registrasi' });
                            else
                                $('#dialog1').load(formUpdateStatusRegistrationUrl + '?id=' + selText + '&registrationId=' + selTextRegistrationId + '&invoiceno=' + selTextInvoiceNo).dialog({ autoOpen: false, modal: true, width: 400, title: 'Update Status Pembayaran' });
                            $("#dialog1").dialog('open');
                        }
                    }
                }
            }

        }

        function hidecoloumn() {
            var userTypeId = "<%= base.UserTypeID %>";
            if (userTypeId == 1 || userTypeId == 2) {
                $("#table").jqGrid('hideCol', ["PreDebtorName"]);
            }
        }
    
    </script>
</asp:Content>
